/*
 * @lc app=leetcode.cn id=6273 lang=cpp
 *
 * [6273] 最多可以摧毁的敌人城堡数目
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class Solution
{
public:
    int find(const vector<int> &forts, int start)
    {
        while (start < forts.size() && !forts[start])
        {
            start++;
        }
        return start;
    }
    int captureForts(vector<int> &forts)
    {
        int ans = 0;

        int l = find(forts, 0);
        int r = find(forts, l + 1);
        while (r < forts.size())
        {
            if(forts[l] != forts[r])
            {
                ans = max(ans, r - l - 1);
            }
            l = r;
            r = find(forts, l + 1);
        }

        return ans;
    }
};
// @lc code=end
